<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta content="text/html;charset=UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title>首页</title>
    <script src="../jquery.min.js"></script>
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <style>
        body {
            background: url("/img/6.jpg");
        }

        /*.container{
            display:table;
            height:100%;
        }

        .row{
            display: table-cell;
            vertical-align: middle;
        }

        .row-centered {
            text-align:center;
        }
        .col-centered {
            display:inline-block;
            float:none;
            text-align:left;
            margin-right:-4px;
        }*/
    </style>
</head>
<body>
<div class="container">
    <div class="row clearfix">
        <form id="form" action="/license/generateLicense2" method="post">
            <div class="col-md-12 column">
            <textarea class="form-control" id="licenseCheckModel" name="licenseCheckModel" rows="16"
                      style="min-width: 90%"></textarea>
                <button type="button" class="btn btn-primary" id="generateLicense">生成授权
                </button>
            </div>
        </form>
    </div>
</div>
<script>
    $(function () {
        $("#generateLicense").on("click", function () {

            var formObject = $("#licenseCheckModel").val();
            var data = {
                "licenseCheckModel": JSON.parse(formObject)
            };
            console.log(data);
            console.log(JSON.stringify(data));


            $.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "/license/generateLicense2",//url
                contentType: "application/json",
                data: JSON.stringify(data),
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    if (result.statusCode == 200) {
                        window.location.href = result.url;
                    } else {
                        alert(result.title);
                    }
                },
                error: function () {
                    alert("异常！");
                }
            })
        });
    });

    /**
     * 自动将form表单封装成json对象
     */
    $.fn.serializeObject = function () {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function () {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
</script>
</body>
</html>